package com.exption;

import com.pancm.result.ResultBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobleException {
    private static final Logger logger = LoggerFactory.getLogger(GlobleException.class);
    @ExceptionHandler(value = GirlException.class)

    public Result girlException( GirlException e){
//        logger.error("发生异常：status{},message{}",e.getExceptionEnum().getCode(),e.getExceptionEnum().getMsg());
        e.printStackTrace();

        logger.error("发生异常{}",e.getMsg());
        return new Result(e.getMsg());
    }
    @ExceptionHandler(value =NullPointerException.class)
    public Enum nullException(NullPointerException e){
        e.printStackTrace();
        logger.error("发生空异常:{}",e.getMessage());
        return ExceptionEnum.NULL;
    }
    @ExceptionHandler(value =Exception.class)
    public Enum unknowExceptin(Exception e){
        e.printStackTrace();
        logger.error("发生异常:{}",e.getMessage());
        return ExceptionEnum.unkonwMsg(e.getMessage());
    }
}
